package com.op.teachingliteapp.fragment.resourcedetails;


import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.op.teachingliteapp.R;



public class ResourceDetailsAdapter extends BaseAdapter{
	private ArrayList<ResourceDetailsDataProvider>  list_ppt;
	 private Context mContext;

	 public ResourceDetailsAdapter(Context mContext,ArrayList<ResourceDetailsDataProvider> list) {
	  this.mContext = mContext;
	  this.list_ppt=list;
	  list_ppt.add(new ResourceDetailsDataProvider("第1章 Java概述",
  			ResourceDetailsFragment.Location + "java_1.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第2章 Java语言基础", ResourceDetailsFragment.Location + "java_2.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第3章 类的封装、继承和多态", ResourceDetailsFragment.Location + "java_3.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第4章 接口、内部类和包", ResourceDetailsFragment.Location + "java_4.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第5章 异常处理",
			  ResourceDetailsFragment.Location + "java_5.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第6章 图形用户界面",
			  ResourceDetailsFragment.Location + "java_6.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("第7章 多线程",
			  ResourceDetailsFragment.Location + "java_7.pdf", R.drawable.pdf));
	  list_ppt.add(new ResourceDetailsDataProvider("云教学",
			  ResourceDetailsFragment.Location + "yunjiaoxue.pdf", R.drawable.pdf));
	 }
	 
	 
		public Context getContext(){
			return mContext;
		}
	 
	 @Override
	 public int getCount() {
		 return list_ppt.size();
	 }

	 @Override
	 public ResourceDetailsDataProvider getItem(int position) {
		 return list_ppt.get(position);
	 }

	 @Override
	 public long getItemId(int position) {
	  return position;
	 }

	@Override
	 public View getView(final int position, View convertView, ViewGroup parent) {

		LinearLayout ll=null;
		if(convertView!=null){
			ll=(LinearLayout)convertView;
			}else{
				ll=(LinearLayout)LayoutInflater.from(getContext()).inflate(R.layout.item_resource_details_ppt,null);
			}
		final ResourceDetailsDataProvider data=getItem(position);
		
		
		ImageView ppt_img = (ImageView)ll.findViewById(R.id.ppt_img);
		TextView ppt_name = (TextView) ll.findViewById(R.id.ppt_name);
	  
	  ppt_img.setImageResource(data.getIconId());
	  ppt_name.setText(data.getName());
	  return ll;
	 }

}
